// run: $exec < input
#include <iostream>

int const maxn = 505;
int a[maxn][maxn];

int n, k;

int main()
{
	std::cin >> n >> k;
	int now = n * n;
	for (int i = 1; i <= n; i++) {
		for (int j = n; j >= k; j--)
			a[i][j] = now--;
	}

	now = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < k; j++)
			a[i][j] = now++;
	}

	int sum = 0;
	for (int i = 1; i <= n; i++) sum += a[i][k];
	std::cout << sum << '\n';
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) std::cout << a[i][j] << ' ';
		std::cout << '\n';
	}
}

